<?php 
defined('RUN_KATANA') or die('Restricted access');
if($adc->getCurrentAd())
{
	unset($buttons);
	$katana->setAction('editor_ad');
	$i = 0;
	if($katana->getId() == 23)
	{
		$buttons[$i]['title'] = ucfirst($txt->getWord('back'));
		$buttons[$i]['href'] = '';
		$buttons[$i]['onclick'] = 'history.go(-1)';
		$buttons[$i]['params']['class'] = 'bold';
	}
	/*
	$i++;
	$buttons[$i]['title'] = '&nbsp;&nbsp;&nbsp;&nbsp;';
	$buttons[$i]['href'] = '?';
	$buttons[$i]['onclick'] = '';
	$buttons[$i]['params']['class'] = 'bold';
	*/
	
	$i++;
	//$buttons[$i]['title'] = ucfirst($txt->getWord('save'));
	//$buttons[$i]['href'] = '';
	//$buttons[$i]['onclick'] = '$(\'#'.$com->getId().'_editor_ad\').submit();';
	//$buttons[$i]['params']['class'] = 'btn btn-primary bold';
	
	$buttons[$i]['title'] = ucfirst($txt->getWord('save'));
	$buttons[$i]['params']['class'] = 'btn btn-primary bold';
	$buttons[$i]['params']['tag'] = 'button';
	$buttons[$i]['params']['type'] = 'submit';
	$buttons[$i]['params']['icon'] = $theme->getIconSetPrefix().'-save';
	
	if($adc->getCurrentAd()->getIsValid())
	{
		$i++;
		$buttons[$i]['title'] = ucfirst($txt->getWord('preview', $words));
		$buttons[$i]['params']['id'] = 'preview-button';
		$buttons[$i]['params']['class'] = 'btn btn-default bold command';
		$buttons[$i]['params']['onmousedown'] = '$(\'#preview\').val(1);';
		$buttons[$i]['params']['onclick'] = '$(\'#'.$com->getId().'_editor_ad\').submit();';
	}
	
	$i++;
	if($adc->getCurrentAd()->getIsCompleted() > 0)
	{
		if(($adc->getCurrentAd()->getIsPaid() > 0) && ($adc->getCurrentAd()->getIsValid()))
		{ 
			$buttons[$i]['title'] = ucfirst($txt->getWord('publish', $words).' '.$txt->getWord('again', $words));
			$buttons[$i]['href'] = '/c/'.$com->getComId().'?list=ad&activate='.$adc->getCurrentAd()->getId().'';
			$buttons[$i]['onclick'] = '';
			$buttons[$i]['params']['class'] = 'btn btn-default bold';
		}
	}
	else
	{
		if($adc->getCurrentAd()->getActive() > 0)
		{ 
			$buttons[$i]['title'] = ucfirst($txt->getWord('set_as').' '.$adc->getCurrentAd()->getIsBoughtText());
			$buttons[$i]['href'] = '/c/'.$com->getComId().'?list=ad&complete='.$adc->getCurrentAd()->getId().'';
			$buttons[$i]['onclick'] = '';
			$buttons[$i]['params']['class'] = 'btn btn-default bold';
		}
		else
		{ 
			if($adc->getCurrentAd()->getIsPaid() > 0)
			{
				if($adc->getCurrentAd()->getIsValid())
				{
					$buttons[$i]['title'] = ucfirst($txt->getWord('publish', $words));
					$buttons[$i]['href'] = '/c/'.$com->getComId().'?list=ad&activate='.$adc->getCurrentAd()->getId().'';
					$buttons[$i]['onclick'] = '';
					$buttons[$i]['params']['class'] = 'btn btn-primary bold';
				}
			}
			else
			{ 
				if($adc->getCurrentAd()->getIsValid())
				{
					$buttons[$i]['title'] = ucfirst($txt->getWord('proceed_to_payement', $words)).' >>';
					$buttons[$i]['href'] = '/c/'.$com->getComId().'?edit=payment&ad='.$adc->getCurrentAd()->getId().'';
					$buttons[$i]['onclick'] = '';
					$buttons[$i]['params']['class'] = 'btn btn-default bold';
				}
			}
		}
	}
	$com->setButtonsContent($buttons);
	
	$com->setButtonsFooter(array 
	(
		0 => array 
		(	
			'title' => ucfirst($txt->getWord('upload')),
			'href' => '',
			'onclick' => 'document.getElementById(\''.$com->getId().'_editor_ad\').submit();',
			'params' => array 
			( 'class' => 'btn btn-default bold', 'id' => 'bold', ),
		)
	));
	$fullSpan = 4;
	?>
	
	<form id="<?php echo $com->Id; ?>_editor_ad" action="<?php echo $katana->getFormAction().'ad='.$adc->getCurrentAdId(); ?>" method="post" enctype="multipart/form-data" name="editor_ad" role="form">
		<?php if($_GET['display'] == 'renew'): ?>
		<table class="com_form" cellpadding="0" border="0" cellspacing="0">
			<tr>
				<td class="vtop" valign="top">
					<fieldset class="com_table_form">
						<legend><?php echo $adc->getSetting('RenewInfo'); ?></legend>
						<?php echo $controller->getForm('ad_renew')->getFieldsHTML(); ?><br />
						<?php $katana->setAction('renew'); ?>
						<?php //echo getButtonsHTML($theme->HFBSets[$theme->ComHFB]['button'], $com->getButtonsContent()); ?>
                        <?php $katana->addAnalyticsTrack("_gaq.push(['_trackPageview', '/ad/renew']);"); ?>
					</fieldset><br />
				</td>
			</tr>
		</table><br clear="all" />
		<?php else: ?> 
			<?php if($_GET['view'] != 'images'): ?>
            	<div class="row-fluid row">
                	<div class="span6 col-md-6 col-sm-6 col-xs-6">
                    	<fieldset>
                            <legend><?php echo ucfirst($txt->getWord('placement')); ?></legend>
                            <?php echo $controller->getForm('editor_ad_cat')->getFieldsHTML(); ?>
                            <?php if($adc->getCurrentAd()->getUsePrice()): ?>
                            <table cellpadding="0" cellspacing="0" border="0" id="editor_ad_price_fields" <?php if(!($adc->getCurrentAd()->getPriceDisplay() > 0)) { echo 'style="display:none;"'; } ?>>
                                <tr>
                                    <?php if($adc->getSetting('UseCurrencies') > 0): ?>
                                        <?php echo $controller->getForm('editor_ad_price')->Fields['PriceCurrency']->getLabelHTML('table_lines'); ?>
                                        <td>&nbsp;</td>
                                        <?php echo $controller->getForm('editor_ad_price')->Fields['PriceLocal']->getLabelHTML('table_lines'); ?>
                                        <td>&nbsp;</td>
                                    <?php else: ?>
                                        <?php echo $controller->getForm('editor_ad_price')->Fields['PriceGlobal']->getLabelHTML('table_lines'); ?>
                                    <?php endif; ?>
                                </tr>
                                <tr>
                                    <?php if($adc->getSetting('UseCurrencies') > 0): ?>
                                        <?php echo $controller->getForm('editor_ad_price')->Fields['PriceCurrency']->getInputHTML('table_inline'); ?>
                                        <td>&nbsp;</td>
                                        <?php echo $controller->getForm('editor_ad_price')->Fields['PriceLocal']->getInputHTML('table_inline'); ?>
                                        <td>&nbsp;</td>
                                    <?php endif; ?>
                                    <?php echo $controller->getForm('editor_ad_price')->Fields['PriceGlobal']->getInputHTML('table_inline'); ?>
                                </tr>
                                <tr>
                                    <?php if($adc->getSetting('UseCurrencies') > 0): ?>
                                        <?php echo $controller->getForm('editor_ad_price')->Fields['PriceCurrency']->getErrorHTML('table_inline'); ?>
                                        <td>&nbsp;</td>
                                        <?php echo $controller->getForm('editor_ad_price')->Fields['PriceLocal']->getErrorHTML('table_inline'); ?>
                                        <td>&nbsp;</td>
                                    <?php else: ?>
                                        <?php echo $controller->getForm('editor_ad_price')->Fields['PriceGlobal']->getErrorHTML('table_inline'); ?>
                                    <?php endif; ?>
                                </tr>
                            </table><br clear="all" />
                            <?php if($adc->getCurrentAd()->getIsBuying() == 0): ?>
                            <?php echo $controller->getForm('editor_ad_price')->Fields['PriceDisplay']->getHTML(); ?>
                            <?php endif; ?>
                            <br clear="all" />
                            <?php endif; ?>
                            <?php echo $controller->getForm('editor_ad_publish')->getFieldsHTML(); ?>
                        </fieldset><br />
                    </div>
                    <div class="span6 col-md-6 col-sm-6 col-xs-6">
                    	<fieldset>
                            <legend><?php echo ucfirst($txt->getWord('ad_information')); ?></legend>
                            <?php echo $controller->getForm('editor_ad')->getFieldsHTML(); ?><br clear="all" />
                        </fieldset><br />
                    </div>
                </div><br clear="all" />
				<table class="com_form" cellpadding="0" border="0" cellspacing="0">
					<?php 
					$formCat = $controller->getForm('editor_form_ad_type_cat');
					if(count($formCat->getFields()) > 0)
					{
						$formCat->setColumns($adc->getSetting('FormCatCols')); ?>
						<tr><td><hr /></td></tr>
						<tr>
							<td class="form_left vtop" valign="top" id="additional-fields">
								<h3><?php echo ucfirst($txt->getWord('additional_information')); ?></h3><br />
								<?php echo $formCat->getFormTableHTML(); ?><br clear="all" />
							</td>
							
						</tr>
					<?php 
					}
					?>
					<tr><td><hr /></td></tr>
				</table><br clear="all" />
                <div class="row-fluid">
                	<div class="span4">
                    	<fieldset class="com_table_form">
                            <legend><?php echo ucfirst($txt->getWord('contact_information')); ?></legend><br />
                            <?php echo $controller->getForm('editor_ad_contact')->getFieldsHTML(); ?><br clear="all" />
                        </fieldset><br />
                    </div>
                    <div class="span4">
                    	<fieldset class="com_table_form">
                            <legend>
                            <?php 
                                if(ucfirst($txt->getWord('sale_location_'.$adc->getCurrentAd()->getTypeId())) != 'Sale_location_'.$adc->getCurrentAd()->getTypeId())
                                { echo ucfirst($txt->getWord('sale_location_'.$adc->getCurrentAd()->getTypeId())); }
                                else
                                { echo ucfirst($txt->getWord('sale_location')); }
                            ?>
                            </legend><br />
                            <?php echo $controller->getForm('editor_ad_location')->getFieldsHTML(); ?><br clear="all" />
                        </fieldset>
                    </div>
                    <div class="span4">
                    	<?php require('map.php'); ?>
                    </div>
                </div>
				<?php echo getButtonsHTML($theme->HFBSets[$theme->ComHFB]['button'], $com->getButtonsContent()); ?>
				<br clear="all" /><hr />
				<div class="command-bar"><?php echo getButtonsHTML($theme->HFBSets[$theme->ComHFB]['button'], $com->getButtonsContent()); ?></div>
			<?php endif; ?>
			<table class="com_form" cellpadding="0" border="0" cellspacing="0">
				<tr>
					<td class="form_right vtop" valign="top" id="upload-images">
						<legend><?php echo ucfirst($txt->getWord('upload').' '.$txt->getWord('images')); ?></legend><br />
						<?php require('editor-images-upload.php');  ?>
					</td>
				</tr>
				<tr>
					<td class="form_left vtop" valign="top" id="editor-images">
						<legend><?php echo ucfirst($txt->getWord('images')); ?></legend><br />
						<?php require('editor-images.php');  ?>
					</td>
				</tr>
				<tr><td><hr /></td></tr>
			</table><br clear="all" /><hr />
			<?php if(($adc->getSetting('UserLevelAdDoc') > 0) && ($user->getPartnerStatus() >= $adc->getSetting('UserLevelAdDoc'))): ?>
			<table class="com_form" cellpadding="0" border="0" cellspacing="0">
				<tr>
					<td class="form_right vtop" valign="top" id="upload-images">
						<legend>
							<?php echo ucfirst($txt->getWord('upload').' '.$txt->getWord('files')); ?>
							 - (<?php echo ucfirst($txt->getWord('documents').' '.$txt->getWord('and').' '.$txt->getWord('brochures')); ?>)
						</legend><br />
						<?php require('editor-files-upload.php');  ?>
					</td>
				</tr>
				<tr>
					<td class="form_left vtop" valign="top" id="editor-files">
						<legend><?php echo ucfirst($txt->getWord('files')); ?></legend><br />
						<p></p>
						<?php require('editor-files.php');  ?>
					</td>
				</tr>
				<tr><td><hr /></td></tr>
			</table><br clear="all" />
			<?php endif; ?>
		<?php endif; ?>
		
		<input id="<?php echo $com->Id; ?>_editor_ad_stealth" type="hidden" name="stealth_<?php echo md5(date("m-d-w")); ?>" value="" />
		<input type="hidden" name="action" value="<?php echo $katana->getAction(); ?>" /> 
		<input type="hidden" name="ad" value="<?php echo $adc->getCurrentAdId(); ?>" />
		<input id="preview" type="hidden" name="preview" value="0" /> 
        <?php $katana->addAnalyticsTrack("_gaq.push(['_trackPageview', '/ad/edit']);"); ?>
	</form>
<?php 
}
?>